package schema

import (
	"lianzi_gos/internal/config"
	"time"

	"lianzi_gos/pkg/util"
)

// 收藏表
type Collect struct {
	ID          string    `json:"id" gorm:"size:20;primarykey;"`   // Unique ID
	UID         string    `json:"uid" gorm:"size:32;index"`        // 用户ID
	ProductId   string    `json:"product_id" gorm:"size:20;index"` // 商品ID
	Description string    `json:"description" gorm:"size:1024"`    // Details about dictionary
	Sequence    int       `json:"sequence" gorm:"index;"`          // Sequence for sorting
	Status      string    `json:"status" gorm:"size:20;index"`     // Status of dictionary (disabled, enabled)
	CreatedAt   time.Time `json:"created_at" gorm:"index;"`        // Create time
	UpdatedAt   time.Time `json:"updated_at" gorm:"index;"`        // Update time

}
type CollData struct {
	CollId    string `json:"coll_id"`
	AttrId    string `json:"attr_id"`
	ProductId string `json:"product_id"`
	GoodsArr
}

func (a *Collect) TableName() string {
	return config.C.FormatTableName("collect")
}

// Defining the query parameters for the `Collect` struct.
type CollectQueryParam struct {
	util.PaginationParam
	UID    string `form:"uid"`
	Price  string `form:"price"`
	Types  string `form:"types"`
	Name   string `form:"name"`
	Status string `form:"-"` // Status of dictionary (disabled, enabled)
}

// Defining the query options for the `Collect` struct.
type CollectQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Collect` struct.
type CollectQueryResult struct {
	Data       Collects
	PageResult *util.PaginationResult
}

// Defining the slice of `Collect` struct.
type Collects []*CollData

func (a Collects) Len() int {
	return len(a)
}

func (a Collects) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

// Defining the data structure for creating a `Collect` struct.
type CollectForm struct {
	ProductId string `json:"product_id" binding:"required"` // 产品ID
}

// A validation function for the `CollectForm` struct.
func (a *CollectForm) Validate() error {
	return nil
}

// Convert `CollectForm` to `Collect` object.
func (a *CollectForm) FillTo(collect *Collect) error {
	collect.ProductId = a.ProductId
	collect.Status = "enabled"
	return nil
}
